package com.ekang.admin.service;


import com.ekang.admin.dao.UserMapper;
import com.ekang.admin.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zcz on 2017/10/27.
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;


    public User getUserByPhone(String phone) {
        return userMapper.getUserByPhone(phone);
    }


    public Integer createUser(User user) {
        return userMapper.insertUser(user);
    }


    public Integer updateUser(User user) {
        return userMapper.updateUser(user);
    }


    public User getUserById(Integer id) throws Exception {
        if (id != null) {
            //throw new Exception("nonodata");
        }
        return userMapper.getUserById(id);
    }


    public Integer deleteUserByIds(Integer... ids) {
        return userMapper.deleteUsers(ids);
    }


    public Integer deleteUserRole(Integer userId, Integer roleId) {
        return userMapper.deleteUserRole(userId, roleId);
    }


    public Integer addUserRole(Integer userId, Integer roleId) {
        return userMapper.addUserRole(userId, roleId);
    }


//    public PagingResp<Role> queryRoleByPaging(PagingReq req) {
//        List<Role> perms = userMapper.queryRoleByPaging(req);
//        Long count = userMapper.queryRoleCountByPaging(req);
//        PagingResp<Role> resp = new PagingResp<Role>();
//        resp.setData(perms);
//        resp.setDraw(req.getDraw());
//        resp.setRecordsTotal(count);
//        resp.setRecordsFiltered(count);
//        return resp;
//    }


}
